home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / refresh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  9.2 KB  |  335 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #include <string.h>
  20. #define    CURSES_LIBRARY    1
  21. #include <curses.h>
  22.  
  23. #ifndef NO_MEMORY_H
  24. #include <memory.h>
  25. #endif
  26.  
  27. /* undefine any macros for functions defined in this module */
  28. #undef    refresh
  29. #undef    wrefresh
  30. #undef    wnoutrefresh
  31. #undef    doupdate
  32. #undef    redrawwin
  33. #undef    wredrawln
  34.  
  35. /* undefine any macros for functions called by this module if in debug mode */
  36. #ifdef PDCDEBUG
  37. #  undef    wattrset
  38. #  undef    mvwprintw
  39. #  undef    wmove
  40. #  undef    wattrset
  41. #  undef    touchwin
  42. #  undef    reset_prog_mode
  43. #endif
  44.  
  45. #ifdef PDCDEBUG
  46. char *rcsid_refresh  = "$Id$";
  47. #endif
  48.  
  49. /*man-start*********************************************************************
  50.  
  51.   Name:                                                       refresh
  52.  
  53.   Synopsis:
  54.       int    refresh(void);
  55.       int    wrefresh(WINDOW *win);
  56.       int    wnoutrefresh(register WINDOW *win);
  57.       int    doupdate(void);
  58.       int    redrawwin(WINDOW *win);
  59.       int    redrawln(WINDOW *win, int beg_line, int num_lines);
  60.  
  61.   X/Open Description:
  62.      The routine wrefresh() copies the named window to the physical
  63.      terminal screen, taking into account what is already there in
  64.      order to optimize cursor movement.
  65.      The routine refresh() does the same, using stdscr as a default
  66.      screen.
  67.      These routines must be called to get any output on the
  68.      terminal, as other routines only manipulate data structures.
  69.      Unless leaveok has been enabled, the physical cursor of the
  70.      terminal is left at the location of the window's cursor.
  71.  
  72.      The wnoutrefresh() and doupdate() routines allow multiple updates
  73.      with more efficiency than wrefresh() alone.  In addition to all 
  74.      of the window structures representing the terminal screen: a physical
  75.      screen, describing what is actually on the screen and a virtual screen,
  76.      describing what the programmer wants to have on the screen.
  77.  
  78.      The wrefresh() function works by first calling wnoutrefresh(),
  79.      which copies the named window to the virtual screen.  It then
  80.      calls doupdate(), which compares the virtual screen to the
  81.      physical screen and does the actual update.  If the programmer
  82.      wishes to output several windows at once, a series of cals to
  83.      wrefresh() will result in alternating calls to wnoutrefresh()
  84.      and doupdate(), causing several bursts of output to the
  85.      screen.  By first calling wnoutrefresh() for each window, it
  86.      is then possible to call doupdate() once.  This results in
  87.      only one burst of output, with probably fewer total characters
  88.      transmitted and certainly less CPU time used.
  89.  
  90.   X/Open Return Value:
  91.      All functions return OK on success and ERR on error.
  92.  
  93.   X/Open Errors:
  94.      No errors are defined for this function.
  95.  
  96.   Portability                             X/Open    BSD    SYS V
  97.                                           Dec '88
  98.       refresh                               Y        Y       Y
  99.       wrefresh                              Y        Y       Y
  100.       wnoutrefresh                          Y        Y       Y
  101.       doupdate                              Y        Y       Y
  102.       redrawwin                             -        -      4.0
  103.       wredrawln                             -        -      4.0
  104.  
  105. **man-end**********************************************************************/
  106.  
  107. /***********************************************************************/
  108. int    refresh( void )
  109. /***********************************************************************/
  110. {
  111. #ifdef PDCDEBUG
  112.     if (trace_on) PDC_debug("refresh() - called\n");
  113. #endif
  114.  
  115.     return( wrefresh(stdscr) );
  116. }
  117. /***********************************************************************/
  118. int    wrefresh(WINDOW *win)
  119. /***********************************************************************/
  120. {
  121. #ifdef PDCDEBUG
  122.     if (trace_on) PDC_debug("wrefresh() - called\n");
  123. #endif
  124.  
  125.     if (win == (WINDOW *)NULL)    return( ERR );
  126.     if (win->_flags & _PAD)    return( ERR );
  127.     if (win->_flags & _SUBPAD)    return( ERR );
  128.  
  129.     if (win == curscr)
  130.         curscr->_clear = TRUE;
  131.     else    
  132.         wnoutrefresh(win);
  133.     doupdate();
  134.     return( OK );
  135. }
  136. /***********************************************************************/
  137. int    wnoutrefresh(WINDOW *win)
  138. /***********************************************************************/
  139. {
  140. register int        first;    /* first changed char on line */
  141. register int        last;    /* last changed char on line  */
  142.     int        begy;    /* window's place on screen   */
  143.     int        begx;
  144.     int        i;
  145.     int        j;
  146.     int        y;
  147.     int        x;
  148.     int        len;
  149.     chtype        attrs;
  150.  
  151. #ifdef PDCDEBUG
  152.     if (trace_on) PDC_debug("wnoutrefresh() - called\n");
  153. #endif
  154.  
  155.     if (win == (WINDOW *)NULL)
  156.         return( ERR );
  157.  
  158.     if ((win->_flags == _PAD)
  159.     ||  (win->_flags == _SUBPAD))
  160.         return( ERR );
  161.  
  162.     y = win->_cury;
  163.     x = win->_curx;
  164.     attrs = win->_attrs;
  165.     if (win->_title != NULL)
  166.         len = strlen(win->_title);
  167.     /*
  168.      * There may be a better place to implement window titles, but this
  169.      * seems to be the best place. -- Frotz
  170.      */
  171.     if ((len > 0) 
  172.     && (win->_title != NULL) 
  173.     && !(win->_flags & _SUBWIN)
  174.     && !(win->_flags & _SUBPAD))
  175.     {
  176.         wattrset(win, win->_title_attr);
  177.         mvwprintw(win, 0, (win->_title_ofs), "%s", (long) win->_title);
  178.         wmove(win, y, x);    /* restore cursor postion */
  179.         wattrset(win, attrs);    /* restore attributes      */
  180.     }
  181.  
  182.     if (win->_flags & _PAD)
  183.         return( ERR );
  184.  
  185.     begy = win->_begy;
  186.     begx = win->_begx;
  187.  
  188.     for (i = 0, j = begy; i < win->_maxy; i++, j++)
  189.     {
  190.         if (win->_firstch[i] != _NO_CHANGE)
  191.         {
  192.             first = win->_firstch[i];
  193.             last = win->_lastch[i];
  194.  
  195.             memcpy(&(curscr->_y[j][begx + first]),
  196.                    &(win->_y[i][first]),
  197.                    (last - first + 1) * sizeof(chtype));
  198.  
  199.             first += begx;    /* s's min/max change positions */
  200.             last += begx;
  201.  
  202.             if (curscr->_firstch[j] != _NO_CHANGE)
  203.                 curscr->_firstch[j] = min(curscr->_firstch[j], first);
  204.             else
  205.                 curscr->_firstch[j] = first;
  206.  
  207.             curscr->_lastch[j] = max(curscr->_lastch[j], last);
  208.  
  209.             win->_firstch[i] = _NO_CHANGE;    /* updated now */
  210.         }
  211.         win->_lastch[i] = _NO_CHANGE;    /* updated now */
  212.     }
  213.  
  214.     if (win->_clear)
  215.     {
  216.         win->_clear = FALSE;
  217.     }
  218.  
  219.     if (!win->_leave)
  220.     {
  221.         curscr->_cury = win->_cury + begy;
  222.         curscr->_curx = win->_curx + begx;
  223.     }
  224.     return( OK );
  225. }
  226. /***********************************************************************/
  227. int    doupdate(void)
  228. /***********************************************************************/
  229. {
  230. register int    i;
  231. bool rc;
  232. #ifdef    REGISTERWINDOWS
  233.     WINDS*    next = _cursvar.visible;
  234. #endif
  235.  
  236. #ifdef PDCDEBUG
  237.     if (trace_on) PDC_debug("doupdate() - called\n");
  238. #endif
  239.  
  240. #ifdef    REGISTERWINDOWS
  241.     if (_cursvar.refreshall)
  242.     {
  243.         while (next != NULL)
  244.         {
  245.             if (next->w->_parent != NULL)
  246.             {
  247.                 touchwin(next->w->_parent);
  248.                 wnoutrefresh(next->w->_parent);
  249.             }
  250.             touchwin(next->w);
  251.             wnoutrefresh(next->w);
  252.             next = next->next;
  253.         }
  254.     }
  255. #endif
  256.  
  257.     if  (_cursvar.shell)
  258.         reset_prog_mode();
  259.  
  260.     if (curscr == (WINDOW *)NULL)
  261.         return( ERR );
  262.  
  263. /* if checking for typeahead, bail out here if any is found */
  264.  
  265.     
  266.     if (_cursvar.refrbrk && (_cursvar.cbreak || _cursvar.raw_inp)) 
  267.     {
  268.         rc = PDC_breakout();     
  269.         if(rc)
  270.             return( OK );
  271.     }
  272.  
  273.     if (curscr->_clear)
  274.     {
  275.         PDC_clr_update(curscr);
  276.     }
  277.     else
  278.     {
  279.         for (i = 0; i < LINES; i++)
  280.         {
  281.             if (curscr->_firstch[i] != _NO_CHANGE)
  282.                 if (PDC_transform_line(i))  /* if test new */
  283.                     break;
  284.         }
  285.     }
  286.  
  287. #if defined (XCURSES)
  288.     XCurses_wait_for_display();
  289. #endif
  290.  
  291.     PDC_gotoxy(curscr->_cury, curscr->_curx);
  292.     _cursvar.cursrow = curscr->_cury;
  293.     _cursvar.curscol = curscr->_curx;
  294.  
  295.     return( OK );
  296. }
  297. /***********************************************************************/
  298. int    redrawwin(WINDOW *win)
  299. /***********************************************************************/
  300. {
  301.     register int i;
  302.  
  303. #ifdef PDCDEBUG
  304.     if (trace_on) PDC_debug("redrawwin() - called\n");
  305. #endif
  306.  
  307.     if (win == (WINDOW *)NULL)
  308.         return( ERR );
  309.  
  310.     return(wredrawln(win,0,win->_maxy));
  311. }
  312. /***********************************************************************/
  313. int    wredrawln(WINDOW *win, int start, int num)
  314. /***********************************************************************/
  315. {
  316.     register int i;
  317.  
  318. #ifdef PDCDEBUG
  319.     if (trace_on) PDC_debug("wredrawln() - called\n");
  320. #endif
  321.  
  322.     if (win == (WINDOW *)NULL)
  323.         return( ERR );
  324.  
  325.     if  (start > win->_maxy || start + num > win->_maxy)
  326.         return( ERR );
  327.     for(i=start;i<start+num;i++)
  328.        {
  329.         win->_firstch[i] = 0;
  330.         win->_lastch[i] = win->_maxx - 1;
  331.        }
  332.     return( OK );
  333. }
  334.